package com.iweb.manager.controller;


import com.iweb.manager.model.record;
import com.iweb.manager.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/record")
public class RecordController {
    @Autowired
    RecordService recordService;

    @GetMapping
    public List<record> selectAllRecord(@RequestParam int user_id) {
        return recordService.selectAllRecord(user_id);
    }

    @GetMapping("/selectOne")
    public record selectOneRecord(@ModelAttribute record record) {
        return recordService.selectOneRecord(record);
    }

    @PostMapping
    public String addOneRecord(@ModelAttribute record record) {
        return recordService.addOneRecord(record) > 0 ? "添加成功" : "添加失败";
    }

    @DeleteMapping
    public String deleteOneRecord(@RequestParam int recordid) {
        return recordService.deleteOneRecord(recordid) > 0 ? "删除成功" : "删除失败";
    }
}
